package com.woniuxy.boot.nb_auth.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.stereotype.Component;

@Component
public class SmsUtil {
    public void Send(Integer code,String phone)  {
        //1，给phoneNumber发送一个随机数字字符串
        DefaultProfile profile = DefaultProfile.getProfile("default", "LTAI5t84iwynYgMQPjRHdC3j", "0CBX6na50B2FWI7qWJNGsWPoI6xJd6");
        DefaultAcsClient client = new DefaultAcsClient(profile);

        //设置相关固定参数
        CommonRequest request = new CommonRequest();
        request.setSysDomain("dysmsapi.aliyuncs.com");//请求阿里云地址，默认不能改
        request.setSysVersion("2017-05-25");//版本号
        request.setSysAction("SendSms");//请求哪个方法
        request.setSysMethod(MethodType.POST); //提交方式，默认不能改
        //设置发送相关参数
        request.putQueryParameter("PhoneNumbers", phone);//设置要发送的【手机号】
        request.putQueryParameter("SignName", "胡汉三回来啦");//申请阿里云短信服务的【签名名称】
        request.putQueryParameter("TemplateCode", "SMS_475010362");//申请阿里云短信服务的【模版中的 模版CODE】

       /* Map<String, Integer> map = new HashMap<>();
        map.put("code", code);*/
        String json="{\"code\":\""+code+"\"}";
        request.putQueryParameter("TemplateParam", json);
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response);
            System.out.println(response.getHttpResponse().isSuccess());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
